export const actions = {
    getInfo({}) {
        return this.$api.warning.getInfo().then((res) => {
            if(res.data.code == 200) {
                return Promise.resolve(res.data.data)
            }
            else {
                this.$router.push("/mainPage/error")
                return Promise.reject(new Error(res.data.msg))
            }
        }, (error) => {
            this.$router.push("/mainPage/error")
            return Promise.reject(error)
        }).catch((error) => {
            this.$router.push("/mainPage/error")
            return Promise.reject(error)
        })
    },
    putIntruder({},{room,ts}){
        return this.$api.warning.putIntruder(room,ts).then((res)=>{
            if(res.data.code == 200)
            {
                return Promise.resolve(res.data.data)
            }
            else
            {
                return Promise.reject(new Error(res.data.msg))
            }
        },(error)=>{
            return Promise.reject(error)
        }).catch((error)=>{
            return Promise.reject(error)
        })
    },
    putTemperature({},{room,ts}){
        return this.$api.warning.putTemperature(room,ts).then((res)=>{
            if(res.data.code == 200)
            {
                return Promise.resolve(res.data.data)
            }
            else
            {
                return Promise.reject(new Error(res.data.msg))
            }
        },(error)=>{
            return Promise.reject(error)
        }).catch((error)=>{
            return Promise.reject(error)
        })
    },
    putHumidity({},{room,ts}){
        return this.$api.warning.putHumidity(room,ts).then((res)=>{
            if(res.data.code == 200)
            {
                return Promise.resolve(res.data.data)
            }
            else
            {
                return Promise.reject(new Error(res.data.msg))
            }
        },(error)=>{
            return Promise.reject(error)
        }).catch((error)=>{
            return Promise.reject(error)
        })
    }
}